package com.ruoyi.financial.controller;

import java.util.List;

import com.ruoyi.financial.domain.FCarCost;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.financial.domain.FCarUse;
import com.ruoyi.financial.service.IFCarUseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 使用记录Controller
 * 
 * @author xunzhe
 * @date 2024-03-13
 */
@Controller
@RequestMapping("/financial/fCarUse")
public class FCarUseController extends BaseController
{
    private String prefix = "financial/fCarUse";

    @Autowired
    private IFCarUseService fCarUseService;

    @RequiresPermissions("financial:fCarUse:view")
    @GetMapping()
    public String fCarUse()
    {
        return prefix + "/fCarUse";
    }

    /**
     * 查询使用记录列表
     */
    @RequiresPermissions("financial:fCarUse:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FCarUse fCarUse)
    {
        startPage();
        List<FCarUse> list = fCarUseService.selectFCarUseList(fCarUse);
        return getDataTable(list);
    }

    /**
     * 导出使用记录列表
     */
    @RequiresPermissions("financial:fCarUse:export")
    @Log(title = "使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FCarUse fCarUse)
    {
        List<FCarUse> list = fCarUseService.selectFCarUseList(fCarUse);
        ExcelUtil<FCarUse> util = new ExcelUtil<FCarUse>(FCarUse.class);
        return util.exportExcel(list, "使用记录数据");
    }

    /**
     * 新增使用记录
     */
    @GetMapping("/add/{carId}")
    public String add(@PathVariable("carId") Long carId, ModelMap mmap)
    {
        mmap.put("carId", carId);
        return prefix + "/add";
    }

    /**
     * 新增保存使用记录
     */
    @RequiresPermissions("financial:fCarUse:add")
    @Log(title = "使用记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FCarUse fCarUse)
    {
        fCarUse.setCreateBy(getLoginName());
        fCarUse.setDeptId(getSysUser().getDeptId());
        return toAjax(fCarUseService.insertFCarUse(fCarUse));
    }

    /**
     * 修改使用记录
     */
    @RequiresPermissions("financial:fCarUse:edit")
    @GetMapping("/edit/{useId}")
    public String edit(@PathVariable("useId") Long useId, ModelMap mmap)
    {
        FCarUse fCarUse = fCarUseService.selectFCarUseByUseId(useId);
        mmap.put("fCarUse", fCarUse);
        return prefix + "/edit";
    }

    /**
     * 修改保存使用记录
     */
    @RequiresPermissions("financial:fCarUse:edit")
    @Log(title = "使用记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FCarUse fCarUse)
    {
        return toAjax(fCarUseService.updateFCarUse(fCarUse));
    }

    /**
     * 删除使用记录
     */
    @RequiresPermissions("financial:fCarUse:remove")
    @Log(title = "使用记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fCarUseService.deleteFCarUseByUseIds(ids));
    }

    @RequiresPermissions("financial:fCarUse:detail")
    @GetMapping("/view/{useId}")
    public String fCar(@PathVariable("useId") Long useId, ModelMap mmap)
    {
        FCarUse fCarUse = fCarUseService.selectFCarUseByUseId(useId);
        mmap.put("fCarUse", fCarUse);
        return prefix + "/view";
    }

    @RequiresPermissions("financial:fCarUse:shenpi")
    @GetMapping("/examine/{useId}")
    public String examine(@PathVariable("useId") Long useId, ModelMap mmap) {
        FCarUse fCarUse = fCarUseService.selectFCarUseByUseId(useId);
        mmap.put("fCarUse", fCarUse);
        return prefix + "/examine";
    }

    @RequiresPermissions("financial:fCarUse:shenpi")
    @Log(title = "使用记录", businessType = BusinessType.UPDATE)
    @PostMapping("/examineSave")
    @ResponseBody
    public AjaxResult examineSave(FCarUse fCarUse) {
        FCarUse newFCarUse = new FCarUse();
        newFCarUse.setUseId(fCarUse.getUseId());
        newFCarUse.setExamineStatus(fCarUse.getExamineStatus());
        newFCarUse.setExamineRemark(fCarUse.getExamineRemark());
        newFCarUse.setExamineBy(getLoginName());

        return toAjax(fCarUseService.examine(newFCarUse));
    }

    @RequiresPermissions("financial:fCarUse:edit")
    @GetMapping("/editExamine/{useId}")
    public String editExamine(@PathVariable("useId") Long useId, ModelMap mmap)
    {
        FCarUse fCarUse = fCarUseService.selectFCarUseByUseId(useId);
        mmap.put("fCarUse", fCarUse);
        return prefix + "/editExamine";
    }

}
